home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / programming / c / supralib / developer / source.org / filetype.c < prev    next >
C/C++ Source or Header  |  1999-06-14  |  1KB  |  55 lines

  1. /****** FileType ****************************************************
  2. *
  3. *   NAME
  4. *       FileType -- Examines if a file is a directory or a file (V10)
  5. *
  6. *   SYNOPSIS
  7. *       type = FileType(filename)
  8. *
  9. *       LONG = FileType(char *);
  10. *
  11. *   FUNCTION
  12. *       Will use dos.library's Examine() function to determine
  13. *       whether a specified file(path) exists, and if it is a file
  14. *       or a directory.
  15. *
  16. *   INPUTS
  17. *       filename - pointer to a filename string
  18. *
  19. *   RESULT
  20. *       returns 0 if specified file/path does not exist. If < 0, then
  21. *       it is a plain file. If > 0 a directory.
  22. *       This function actually returns fib_DirEntryType (from
  23. *       struct FileInfoBlock).
  24. *
  25. *   EXAMPLE
  26. *
  27. *       type = FileType("SYS:System");
  28. *
  29. *       type will be > 0, which means that "SYS:System" is a dir.
  30. *
  31. *******************************************************************/
  32.  
  33.  
  34. #include<proto/dos.h>
  35. #include<dos/dos.h>
  36.  
  37. LONG FileType(char *file)
  38. {
  39.     struct FileInfoBlock fib;
  40.     BPTR lock;
  41.     LONG type=0;
  42.  
  43.     if (lock = Lock(file, ACCESS_READ)) {
  44.         if (Examine(lock, &fib)) {
  45.             type = fib.fib_DirEntryType;
  46.         }
  47.         UnLock(lock);
  48.     }
  49.  
  50.     return(type);
  51. }
  52.  
  53.  
  54.  
  55.